console.log('ok');
$('#btnQuery').click(function () {
    let keyword = $('[name=keyword]').val();
    let obj =
    {
        keyword
    }
    $.post('/Product/query', obj, function (res) {
        console.log(res);
        let tt = $('#tt');
        let tb = $('.tb');
        tb.html('')
        res.forEach(item => {
            let html =
                `<tr class="tb">
                        <td>${item.id}</td>
                        <td>${item.studentName}</td>
                        <td>${item.remarks}</td>
                        <td>
                            <input class="btnEdit" type="button" value="编辑" onclick="btnEdit(${item.id})">
                            <input class="btnDel" type="button" value="删除" onclick="btnDel(${item.id})">
                        </td>
                </tr>
                `
            tt.append(html);
        })
    })
})



$('#btnAdd').click(function () {
    window.location.href = '/Product/createOrEdit'
})



$('#btnSave').click(function () {
    let id = $('[name=id]').val();
    let ProductName = $('[name=ProductName]').val();
    let supplier = $('[name=supplier]').val();
    let price = $('[name=price]').val();
    let stock = $('[name=stock]').val();
    let remarks = $('[name=remarks]').val();
    let obj =
    {
        id,
        ProductName,
        supplier,
        price,
        stock,
        remarks
    }
    console.log(obj);
    $.post('/product/save', obj, function (res) {
        console.log(res);
        window.location.href = '/product/index'
    })
})


$('#btnCancel').click(function () {
    window.location.href = '/product/index'
})


function btnEdit(id) {
    window.location.href = `/product/createOrEdit/${id}`
}

function btnDel(id) {
    let del = '确认删除？'
    if (confirm(del)) {
        window.location.href = `/product/Delete/${id}`
    } else {
        console.log('取消删除！')
    }
}